<template>
  <div>
    <el-row class="formStyle">
      <el-col :offset="6" :span="12" align="middle">
        <el-row class="card">
          <el-col>
            <label>医院设置</label>
            <el-form :model="hospitalSetForm" ref="hospitalSetForm">
              <el-input v-model="hospitalSetForm.id" prop="id" v-show="false" />
              <el-form-item label="医院名称" prop="hosname">
                <el-input v-model="hospitalSetForm.hosname" />
              </el-form-item>
              <el-form-item label="医院编号" prop="hoscode">
                <el-input v-model="hospitalSetForm.hoscode" />
              </el-form-item>
              <el-form-item label="api基础路径" prop="apiUrl">
                <el-input v-model="hospitalSetForm.apiUrl" />
              </el-form-item>
              <el-form-item label="联系人姓名" prop="contactsName">
                <el-input v-model="hospitalSetForm.contactsName" />
              </el-form-item>
              <el-form-item label="联系人手机" prop="contactsPhone">
                <el-input v-model="hospitalSetForm.contactsPhone" />
              </el-form-item>
              <el-form-item>
                <el-button
                  size="medium"
                  type="success"
                  v-loading="loading"
                  @click="saveOrUpdate"
                  >保存</el-button
                >
                <el-button size="medium" type="info" @click="back">返回</el-button>
                <el-button size="medium" type="info" @click="reset">重置</el-button>
              </el-form-item>
            </el-form>
          </el-col>
        </el-row>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import { save, detail, edit } from "@/api/hospset";
export default {
  name: "hospsetForm",
  components: {},
  props: {},
  data() {
    return {
      hospitalSetForm: {},
      loading: false,
    };
  },

  created() {
    this.init();
  },
  methods: {
    init() {
      if (this.$route.params && this.$route.params.id) {
        this.hospitalSetForm.id = this.$route.params.id;
      }
      this.getdetail();
    },
    getdetail() {
      let id = this.hospitalSetForm.id;
      if (id) {
        detail(id).then((res) => {
          this.hospitalSetForm = res.data;
        });
      }
    },
    saveOrUpdate() {
      if (this.hospitalSetForm.id) {
        edit(this.hospitalSetForm).then((res) => {
          if (res.code == 200) {
            this.$message.success("修改成功");
            this.loading = false;
            this.back();
          }
        });
      } else {
        this.loading = true;
        save(this.hospitalSetForm).then((res) => {
          if (res.code == 200) {
            this.$message.success("添加成功");
            this.loading = false;
            this.back();
          }
        });
      }
    },
    back() {
      this.reset();
      this.$router.push({ path: "/hospSet/list" });
    },
    reset() {
      this.$refs["hospitalSetForm"].resetFields();
      this.getdetail();
    },
  },
  watch: {},
  computed: {},
  mounted() {},
};
</script>
<style scoped>
.formStyle {
  margin-top: 5%;
}
</style>
